-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for ASGI lifespan #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
f55750b to
d9fd56e
Compare
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
src/connectrpc/_server_async.py
Outdated
|
|
||
|
|
||
| class ConnectASGIApplication(ABC): | ||
| class ConnectASGIApplication(Generic[_SVC]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this class has abstract methods, maybe it should also inherit from ABC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, not sure why I thought Generic would imply that - fixed
|
@i2y Can you give this another look? Also @stefanvanburen @spenczar in case this went under the radar. Thanks! |
sorry, I just realized.. |
I realized we need to support lifespan events to allow asyncio startup / shutdown logic for an app. The simplest way to expose this to users seemed to be accepting either a service or an async generator of a service in the application and resolve either within the lifespan events. We fallback to resolving on first request if the server doesn't support lifespan (this is basically just applying interceptors and shouldn't be a too-large first request penalty), one that notably doesn't is the httpx mock transport we recommend for unit tests.
Let me know any thoughts including the general approach.